{template 'public/header'}

{template 'public/comhead'}

<link rel="stylesheet" type="text/css" href="../addons/yzzc_sun/template/public/ygcss.css">

<ul class="nav nav-tabs">
    <span class="ygxian"></span>
    <div class="ygdangq">当前位置:</div>
    <li class="active"><a href="javascript:void(0);">车型分类</a></li>
    <li><a href="{php echo $this->createWebUrl('goods');}"><i class="fa fa-refresh"></i>返回车型列表</a></li>
</ul>
<div class="main ygmain">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <div class="panel panel-default ygdefault">

            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">添加分类名称</label>
                    <div class="col-sm-9">
                        <input type="text" name="name" class="form-control col-sm-3 " value="{$info['name']}" style="width: 390px;" />
                        <input type="submit" name="submit" value="提交" class="btn " style="color: white;background-color: #444444;margin-left: 50px;;"/>
                    </div>
                </div>
            </div>


            <input type="hidden" name="token" value="{$_W['token']}" />
            <input type="hidden" name="id" value="{$info['id']}" />
        </div>
    </form>
    <div class="panel panel-default ygdefault">
        <div class="panel-heading wyheader">

            分类列表

        </div>
    </div>
    <div class="panel-body" style="padding: 0px 15px;">
        <div class="row" id="accordion">

            <table class="yg5_tabel col-md-12">

                <tr class="yg5_tr1" style="border-bottom: 1px solid #efefef;font-weight: bold;text-align: center;">
                    <td  style="text-align: center;">编号</td>
                    <td  style="text-align: center;">分类名称</td>
                    <td>操作</td>
                </tr>

                {loop $info $key $item}
                <tbody>
                <tr class="yg5_tr2" style="border-bottom: 1px solid #efefef;font-weight: bold;text-align: center;">

                    <td>{$item['id']}</td>
                    <td>{$item['name']}</td>
                    <td>
                        <a class="storespan btn btn-xs" onclick="del({$item['id']},{$item['num']})">
                            <span class="fa fa-trash-o"></span>
                            <span class="bianji">删除
                                    <span class="arrowdown"></span>
                                </span>
                        </a>
                        <a href="javascript:void(0);" class="storespan btn btn-xs" data-toggle="modal" data-target="#myModal{$item['id']}">
                            <span class="fa fa-pencil"></span>
                                <span class="bianji">编辑
                                    <span class="arrowdown"></span>
                                </span>
                        </a>
                    </td>
                </tr>
                </tbody>
                <div class="modal fade" id="myModal{$item['id']}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog" role="document">
                          <div class="modal-content">
                            <div class="modal-header">
                              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                              <h4 class="modal-title" id="myModalLabel" style="font-size: 20px;">输入分类名称</h4>
                            </div>
                            <form action="" method="get" >
                                <input type="hidden" name="c" value="site" />
                                <input type="hidden" name="a" value="entry" />
                                <input type="hidden" name="m" value="yzzc_sun" />
                                <input type="hidden" name="do" value="cartype" />
                                <input type="hidden" name="id" value="{$item['id']}" />
                                <input type="hidden" name="op" value="update" />
                                <div class="modal-body" style="font-size: 20px">
                                      <label  control-label">名称</label>
                                      <input type="text" name="name"  class="form-control" value='{$item['name']}'/>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <input type="submit" class="btn btn-info" name="submit" value="确定"/>
                                </div>
                                <input type="hidden" name="token" value="{$_W['token']}"/>
                            </form>
                          </div>
                        </div>
                      </div>
                {/loop}
                {if empty($item)}
                <tr class="yg5_tr2">
                    <td colspan="8">
                       暂无分类
                    </td>
                </tr>
                {/if}
            </table>
        </div>
    </div>

</div>
<script type="text/javascript">
    $(function(){
        $("#frame-7").show();
        $("#yframe-7").addClass("wyactive");
    })
    function del(id,num) {
        if(num>0){
            alert('当前分类下有'+num+'辆车，无法删除，请先修改车辆所属类型')
        }else{
            var ret = confirm("您确定删除吗？")
            if (ret==true){
                $.ajax({
                    type:"POST",
                    url:"/web/index.php?c=site&a=entry&op=delete&do=cartype&op=delete&module_name=yzzc_sun&version_id=1",
                    dataType:"JSON",
                    data:{id:id},
                    success:function(res){
                        console.log(res);
                        location.reload();

                    }
                })
            }
        }

    }
</script>